package com.changpay.zywy.ui.activity.mine

import android.text.TextUtils
import android.view.View
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.base.IView
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.ext.sss
import com.changpay.zywy.http.RetrofitHelper
import kotlinx.android.synthetic.main.activity_change_phone_pw.*
import kotlinx.android.synthetic.main.title_layout.*

class ChangePhonePwActivity : BaseActivity(), IView {
    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    override fun showDefaultMsg(msg: String) {
        showToast(msg)
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun showError(errorMsg: String) {
        showToast(errorMsg)
    }


    private val onClickListener = View.OnClickListener { view ->
        when (view.id) {
            R.id.iv_back -> finish()
            R.id.change_pw_submit -> changeLoginPassword()
//            R.id.setting_three->
//            R.id.setting_four->
//            R.id.setting_five->
//            R.id.setting_six->
//            R.id.setting_out_login->
        }
    }

    private fun changeLoginPassword() {
        val old_password = change_pw_one.getInputText()
        val new_password = change_pw_two.getInputText()
        val comfit_password = change_pw_three.getInputText()
        if (TextUtils.isEmpty(old_password)) {
            showToast("请输入原登录密码")
            return
        }
        if (TextUtils.isEmpty(new_password)) {
            showToast("请输入新的登录密码")
            return
        }
        if (TextUtils.isEmpty(new_password)) {
            showToast("请再次输入新的登录密码")
            return
        }
        if (new_password != comfit_password) {
            showToast("两次输入密码不一致，请重新输入")
            return
        }

        val params = HashMap<String, String>()
        params["key"] = token
        params["old_pwd"] = old_password
        params["new_pwd"] = new_password
        params["re_new_pwd"] = comfit_password
        RetrofitHelper.service.changeLoginPw(params).sss(this)
        {
            showToast(it.result.toString())
            finish()
        }
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_change_phone_pw
    }

    override fun initData() {

    }

    override fun initView() {
        tv_title.text = "修改登录密码"
        iv_back.setOnClickListener(onClickListener)
        change_pw_submit.setOnClickListener(onClickListener)
    }

    override fun start() {

    }
}
